import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/pages/mine/message_center/advertise_message/advertise_message_controller.dart';
import 'package:yt_devops/pages/mine/message_center/advertise_message/advertise_message_detail/advertise_message_detail_controller.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/enums.dart';

class AdvertiseMessageDetailPage
    extends GetView<AdvertiseMessageDetailController> {
  AdvertiseMessageDetailPage({Key? key}) : super(key: key);
  @override
  final controller = Get.put(AdvertiseMessageDetailController());
  final advertiseController = Get.put(AdvertiseMessageController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AdvertiseMessageDetailController>(
      init: controller,
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            backgroundColor: Colour.backgroundColor,
            elevation: 0.1,
            title: Text(
              ResKey.announcementDetails.tr,
              style: const TextStyle(color: Colour.black),
            ),
            leading: IconButton(
              icon: Icon(
                Platform.isAndroid ? Icons.arrow_back : Icons.arrow_back_ios,
                color: Colors.black,
              ),
              onPressed: () {
                if (controller.advertiseDetailModel.status ==
                    AdvertiseStatusType.normal.value) {
                  advertiseController.updateAnnouncementStatus(
                    [controller.advertiseDetailModel.noticeId],
                  );
                }

                Get.back();
              },
            ),
          ),
          body: Container(
            margin: EdgeInsets.symmetric(
              horizontal: 16.w,
              vertical: 16,
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: double.infinity,
                  height: 53,
                  alignment: Alignment.centerLeft,
                  decoration: const BoxDecoration(
                    border: Border(
                      // top: BorderSide(
                      //   width: 1,
                      //   color: Colour.dividerColor,
                      // ),
                    ),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Expanded(
                        child: Text(
                          controller.advertiseDetailModel.noticeTitle!,
                          style: TextStyle(
                            fontSize: 18.sp,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                      ),
                      Text(
                        controller.advertiseDetailModel.updateTime!
                            .replaceAll('-', '/'),
                        style: TextStyle(
                          fontSize: 12.sp,
                          fontWeight: FontWeight.normal,
                          color: Colour.lightTextColor,
                        ),
                      ),
                    ],
                  ),
                ),
                Text(
                  controller.advertiseDetailModel.noticeContent!,
                  textAlign: TextAlign.start,
                  style: TextStyle(
                    color: Colour.mainTextColor,
                    fontSize: 14.sp,
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
